package com.woniuxy.servicelayer.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.dal.entity.Test;
import com.woniuxy.dal.entity.Testtype;
import com.woniuxy.dal.mapper.TestMapper;
import com.woniuxy.dal.mapper.TesttypeMapper;
import com.woniuxy.dal.vo.TestVo;
import com.woniuxy.servicelayer.TesttypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author rjq51
* @description 针对表【testType】的数据库操作Service实现
* @createDate 2023-03-27 17:02:43
*/
@Service
public class TesttypeServiceImpl extends ServiceImpl<TesttypeMapper, Testtype>
    implements TesttypeService {

    @Autowired
    TesttypeMapper testtypeMapper;

    @Autowired
    TestMapper testMapper;


    /**
     * 实验分类查询
     */
    @Override
    public List<TestVo> testClassificationQuery() {
        List<TestVo> testVoList = new ArrayList<>();
        List<Testtype> testTypes = testtypeMapper.selectList(null);
        if(testTypes != null && testTypes.size() > 0) {
            for (Testtype testtype : testTypes) {
                TestVo testVo = new TestVo(testtype.getTestTypeId(), testtype.getTestTypeName(), null);
                QueryWrapper<Test> testQueryWrapper = new QueryWrapper<>();
                testQueryWrapper.eq("testType", testtype.getTestTypeId());
                List<Test> tests = testMapper.selectList(testQueryWrapper);
                testVo.setTestList(tests);
                testVoList.add(testVo);
            }
        }
        return testVoList;
    }

}




